﻿/*
 * 作者：范虹霞
 * 功能描述：区块的相关操作
 * 时间：2018-1-19
 * 修改人：
 * 修改时间：
 *
 */

using Common;
using DataAccess;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataBusiness
{
    public class AreaBLL
    {

        #region 返回区块信息
        /// <summary> 根据条件查询用户信息 </summary>
        /// <param name="AreaName">区块名称</param>
        /// <returns>返回区块信息</returns>
        //public static tb_AreaModel GetArea(string AreaName)
        //{
        //    string sSql = null;

        //    sSql = "SELECT ID,Name,ReservoirType,AcidType,ExplorationDate,ExploitDate,ExploitStyle,ExistingWells,BlockLocation,Start_Location,EndLocation,BlockArea,FROM [tb_Area] WHERE [Name]='" + AreaName + "'";

        //    DataTable dt = SqlHelper.QuerySql(sSql).Tables[0];
        //    //tb_AreaModel area = new tb_AreaModel();
        //    //area.Name = dt.AsEnumerable().Select(d => d.Field<string>("Name")).ToString();
        //    //area.ReservoirType = dt.AsEnumerable().Select(d => d.Field<string>("ReservoirType")).ToString();
        //    //area.AcidType = dt.AsEnumerable().Select(d => d.Field<string>("AcidType")).ToString();
        //    //area.ExplorationDate = dt.AsEnumerable().Select(d => d.Field<DateTime>("ExplorationDate"));
        //    //area.AcidType = dt.AsEnumerable().Select(d => d.Field<string>("AcidType")).ToString();
        //    //area.AcidType = dt.AsEnumerable().Select(d => d.Field<string>("AcidType")).ToString();
        //    //area.AcidType = dt.AsEnumerable().Select(d => d.Field<string>("AcidType")).ToString();
        //    //area.AcidType = dt.AsEnumerable().Select(d => d.Field<string>("AcidType")).ToString();
        //    return area;

        //}
        #endregion

        /// <summary>
        /// 判断区块名称是否已经存在
        /// </summary>
        /// <param name="name">区块名称</param>
        /// <returns></returns>
        public static Boolean IFExistArea(string name)
        {
            string sSql = null;
            sSql = "SELECT 1 FROM [tb_Area] WHERE [Name]='" + name + "'";
            return SqlHelper.QuerySql(sSql).Tables[0].Rows.Count != 0;
        }

        /// <summary>
        /// 新建区块
        /// </summary>
        /// <param name="t">Area模型</param>
        /// <returns></returns>
        public static string AddArea(tb_AreaModel t)
        {
            if (IFExistArea(t.Name))
            {
                return "exist";
            }
            else
            {
                string sSql = @"INSERT INTO[tb_Area]( Name, ReservoirType, AcidType, ExplorationDate, ExploitDate, ExploitStyle, ExistingWells, BlockLocation, Start_Location,EndLocation, 
                    BlockArea, UserID, InputDate)VALUES(@Name, @ReservoirType, @AcidType, @ExplorationDate, @ExploitDate, @ExploitStyle, @ExistingWells, @BlockLocation, @Start_Location,@EndLocation, @BlockArea, NEWID(), @InputDate)";
                SqlParameter[] Paras = new SqlParameter[13];
                Paras[0] = new SqlParameter("@UserID", AppPara.Global_User_Id);
                Paras[1] = new SqlParameter("@Name", t.Name);
                Paras[2] = new SqlParameter("@ReservoirType", t.ReservoirType);
                Paras[3] = new SqlParameter("@AcidType", t.AcidType);
                Paras[4] = new SqlParameter("@ExplorationDate", t.ExplorationDate);
                Paras[5] = new SqlParameter("@ExploitStyle", t.ExploitStyle);
                Paras[6] = new SqlParameter("@ExistingWells", t.ExistingWells);
                Paras[7] = new SqlParameter("@BlockLocation", t.BlockLocation);
                Paras[8] = new SqlParameter("@Start_Location", t.Start_Location);
                Paras[9] = new SqlParameter("@EndLocation", t.EndLocation);
                Paras[10] = new SqlParameter("@BlockArea", t.BlockArea);
                Paras[11] = new SqlParameter("@InputDate", DateTime.Now.ToString());
                Paras[12] = new SqlParameter("@ExploitDate", t.ExploitDate);
                return SqlHelper.ExeSql(sSql, Paras).ToString();
            }
        }

    }
}
